<template>
	<view class="container" style="padding-bottom: 120rpx;">
		<u--form ref="formForm" :model="form">
			<u-form-item label="" prop="box" style="display: flex;">
				<span style="margin-right: 20rpx;">容器码</span>
				<u--input 
					placeholder="请输入/扫描" 
					v-model="form.containerCode" 
					suffixIcon="scan" 
					suffixIconStyle="font-size: 68rpx"
					style="flex: 1;"
				>
				</u--input>
			</u-form-item>
		</u--form>
		<u--form ref="formForm" :model="form">
			<u-form-item label="" prop="box" style="display: flex;">
				<span style="margin-right: 20rpx;">储位码</span>
				<u--input 
					placeholder="请输入/扫描" 
					v-model="form.storageCode" 
					suffixIcon="scan" 
					suffixIconStyle="font-size: 68rpx"
					style="flex: 1;"
				>
				</u--input>
			</u-form-item>
		</u--form>
		<view style="position: fixed;left: 0;bottom: 0;width: 100%;padding: 10rpx;box-sizing: border-box; display: flex;gap: 20rpx;background-color: #fff;">
			<u-button type="primary" @click="submit">确认解绑</u-button>
			<u-button type="warning" @click="reset">重置</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import { unbindStorageAPI } from '@/api/work/storage.js'
	export default {
		data() {
			return {
				form: {
					containerCode: '',
					storageCode: ''
				},
			};
		},
		onLoad(options) {
			uni.$on('scancodedate',(data) => this.getCode(data.code))
		},
		onUnload() {  
		  // 移除监听事件      
		  uni.$off('scancodedate')
		},
		methods: {
			getCode(code) {
				// this.form.containerCode = code
			},
			reset() {
				this.form = {
					containerCode: '',
					storageCode: ''
				}
			},
			async submit() {
				const res = await unbindStorageAPI(this.form)
				if (res.meta.code === 200) {
					this.$refs.uToast.show({
						type: 'success',
						message: res.meta.msg
					})
					this.form = {
						containerCode: '',
						storageCode: ''
					}
				} else {
					this.$refs.uToast.show({
						type: 'warning',
						message: res.meta.msg
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
